<template>
  <div>
    <!-- B端月度指标查询 -->
    <TopFilter :list="topFilterList" :cols="3" @filterChange="changeHandle" @onCollapse="collapseHandle" :labelWidth="110"></TopFilter>

    <Spin :spinning="exportLoading" tip="Loading...">
      <FilterTable
        ref="table"
        columnsRef="MonthTargetQuerySideB"
        :columns="columns"
        :fetchapi="fetchApi"
        :params="fetchParams"
        :datakey="'records'"
        :isSelectColumn="false"
        :onColumnsChange="columns => (this.columns = columns)"
      >
      </FilterTable>
    </Spin>
  </div>
</template>
<script>
import moment, { months } from 'moment';
import { queryList,querySeriesList } from '@/api/dealerSale/salesPlan/MonthTargetQuerySideB';
import { dictionary } from '@/utils/dictMixin';
export default {
  name: 'MonthTargetQuerySideB',
  mixins: [dictionary],
  data() {
    this.BaseTable = null;
    return {
      topFilterList: this.createdFrom(),
      columns: this.createdTable(),
      fetchApi: queryList,
      fetchParams: {},
      formData: {},
      visible: false,
      isDealer: false,
      exportLoading: false
    };
  },
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
  },
  created() {
    this.querySeriesList();
  },
  methods: {
    changeHandle(params) {
      this.fetchParams = Object.assign({}, this.fetchParams, params);
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    selectChangeHandle(row) {},

    detailHandle(row) {
      this.visible = true;
      this.formData = row;
    },
    emitCloseHandler(val, type) {
      this.visible = val;
      if (type === 'refresh') {
        // 重新加载
        this.fetchParams = { ...this.fetchParams };
      }
    },
        // 车系 querySeriesList
    async querySeriesList() {
      const res = await querySeriesList();
      if (res.resultCode === 200) {
        res.data.map(x => {
          this.topFilterList.find(item => item.fieldName == 'seriesId').itemList.push({ text: x.seriesName, value: x.seriesId });
        });
      }
    },
    createdFrom() {
      return [
        {
          type: 'DATE',
          label: '指标月份',
          fieldName: 'targetYearAndMonth',
          initialValue: moment().add(1,'months').format('YYYY-MM'),
          dateType: 'month'
        },
        {
          type: 'SELECT',
          label: '车系名称',
          fieldName: 'seriesId',
          placeholder: '请选择',
          itemList: []
        }
      ];
    },
    createdTable() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '状态',
          dataIndex: 'status',
          sorter: true,
          filter: true,
          filterType: 'input',
          render: props => {
            return <span>{this.createDictText(props.row.status, '2402')}</span>;
          }
        },
        {
          title: '销售区域',
          dataIndex: 'deptName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '省份',
          dataIndex: 'provinceName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '城市',
          dataIndex: 'cityName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '经销商代码',
          dataIndex: 'ownerCode',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '经销商名称',
          dataIndex: 'dealerName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '车系名称',
          dataIndex: 'seriesName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '指标月份',
          dataIndex: 'targetYearAndMonth',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '任务数量（结算）',
          dataIndex: 'targetNum',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '任务数量（终端）',
          dataIndex: 'targetRetailNum',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '下发日期',
          dataIndex: 'assignDate',
          sorter: true,
          filter: true,
          filterType: 'date-range',
          dateFormat: 'yyyy-MM-dd'
        },
         {
          title: '下发人',
          dataIndex: 'assignPersonName',
          sorter: true,
          filter: true,
          filterType: 'input'
        }
      ];
    }
  }
};
</script>
